'use strict' import { getBotComments, saveBotComment, Comment } from '../storageService' import { WrongInputError, NotFoundError, InternalError } from '../../../utils/customErrors' import { Request } from 'express' /** * Operations on /bots/{id}/comments */ export default { /**Returns list of comments for given bot */ async getComments(req: Request) { try { return await getBotComments(req.params.id) } catch (error) { console.error('CANNOT GET COMMENTS', error) throw new InternalError(error) } }, /**Creates a new comment for given bot */ async postComment(req: Request) { const comment: Comment = req.body if (comment) { try { await saveBotComment(req.params.id, comment) return { comment } } catch (error) { console.error("CAN'T INSERT COMMENT", error) throw new InternalError(error) } } else { throw new WrongInputError('body does not contain element "comment"') } } }